package demo4;

abstract class Animal {
    public String name;
    public int age;

    public Animal(String name,int age) {
        this.name = name;
        this.age = age;
    }

    public abstract void eat();
}

interface IFly {
    void fly();
}

interface IRun {
    void run();
}

interface ISwim {
    void swim();
}

class Dog extends Animal implements IRun {
    public Dog(String name,int age) {
        super(name,age);
    }

    @Override
    public void run() {
        System.out.println(this.name+" 正在用4条腿跑！！！");
    }

    @Override
    public void eat() {
        System.out.println(this.name+" 正在吃狗粮！！");
    }
}

class Frog extends Animal implements IRun,ISwim {
    public Frog(String name,int age) {
        super(name,age);
    }

    @Override
    public void run() {
        System.out.println(this.name+" 正在用两个腿 跳着跑！！！");
    }

    @Override
    public void swim() {
        System.out.println(this.name+" 正在蛙泳！！！ ");
    }

    @Override
    public void eat() {
        System.out.println(this.name+" 正在吃蛙粮！！");
    }
}

class Duck extends Animal implements IRun,ISwim,IFly {

    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void fly() {
        System.out.println(this.name+" 正在用 翅膀扇动着 飞！！");
    }

    @Override
    public void run() {
        System.out.println(this.name+" 正在用 两只脚脚 跑！！");
    }

    @Override
    public void swim() {
        System.out.println(this.name+" 正在用 两只脚脚 划着游泳！！");
    }

    @Override
    public void eat() {
        System.out.println(this.name+" 正在吃鸭粮！！");
    }
}


class Robot implements IRun {
    @Override
    public void run() {
        System.out.println("机器人用两个脚在跑");
    }
}
public class Test {

    public static void func1(Animal animal) {
        animal.eat();
    }

    public static void running(IRun iRun) {
        iRun.run();
    }

    public static void flying(IFly iFly) {
        iFly.fly();
    }

    public static void swimming(ISwim iSwim) {
        iSwim.swim();
    }

    public static void main(String[] args) {
        running(new Duck("唐老鸭",1));
        running(new Dog("二狗子",1));
        running(new Frog("青蛙",1));

        running(new Robot());

        System.out.println("===============");

        flying(new Duck("唐老鸭",1));
        System.out.println("================");

        swimming(new Duck("唐老鸭",1));
        swimming(new Frog("青蛙",1));

    }

    public static void main1(String[] args) {
        func1(new Duck("唐老鸭",1));
        func1(new Dog("二狗子",1));
        func1(new Frog("青蛙",1));
    }
}
